// map.js
import qqmap from '../../../utils/qqmap'
Page({
  data: {
    id:'',
    latitude: 40.060539,
    longitude: 116.343847,
    detali:{},
    markers:[
      { 
        id:1,
        latitude:30.335661,
        longitude:116.01841,
      },
      { 
        id:2,
        latitude:30.335675,
        longitude:117.01842,
      }
    ],
    polyline:[
      {
        points:[
          {
            latitude:30.335661,
            longitude:116.01841,
          },
          {
            latitude:30.535661,
            longitude:116.81841,
          },
        ],
        width:10,
        color:'#00b26a',
      }
    ]
  },
  onLoad({id}){
     this.getDetail(id)
     this.setData({id})
  },
  goRepair(){
    wx.navigateTo({
      url: `/repair_pkg/pages/form/index?id=${this.data.id}`,
    })
  },
  async getDetail(id){
     const res = await wx.http({url:'/repair/'+id})
     console.log(res);
     this.setData({detail:res.data})
     this.geocoder()
  },
  // 地图当前的位置，地名确定位置
  geocoder(){
    qqmap.geocoder({
      address:'安徽省宿松县火车站',
      success:(res) => {
        console.log(res);
        const {lat,lng} = res.result.location
        this.setData({latitude:lat,longitude:lng})
      }
    })
  },
  // 取消保修
  goCancle(){
    wx.showModal({
      title: '取消保修',
      content: '您确认要取消吗',
      success: async (e)=>{
        if(e.confirm){
          await wx.http({url:`/cancel/repaire/${this.data.id}`,method:'put'})
        }
        wx.showToast({
          title: '成功',
        })
        setTimeout(()=>{
          wx.navigateTo({
            url: '/repair_pkg/pages/list/index',
          })
        },1000)
      }
    })
  }
})
